import type { CreateCrudOptionsRet, CrudExpose } from '@fast-crud/fast-crud';

import type { FormRulesExt } from '#/api';
import type { ActionEnum } from '#/enums/commonEnum';

import { BaseOrgApi } from '#/api/basic/user/baseOrg';
import { DictEnum } from '#/enums/commonEnum';
import { backendDict, STATE_CONSTANT_DICT } from '#/plugins/fast-crud/common';

export function createCrudOptions(): CreateCrudOptionsRet {
  return {
    crudOptions: {
      request: {
        addRequest: BaseOrgApi.addRequest,
        editRequest: BaseOrgApi.editRequest,
      },
      form: {
        // 单列布局
        col: { span: 24 },
        // label 宽度
        labelCol: { span: null, style: { minWidth: '80px' } },
      },
      addForm: { mode: 'add' },
      editForm: { mode: 'edit' },
      columns: {
        id: {
          title: 'id',
          form: {
            show: false,
          },
          type: 'text',
        },
        parentId: {
          title: '父ID',
          type: 'text',
          form: {
            show: false,
          },
        },
        parentName: {
          title: '父节点',
          type: 'text',
          form: {
            component: {
              disabled: true,
            },
            value: '根节点',
          },
        },
        name: {
          title: '名称',
          type: 'text',
        },
        type: {
          title: '类型',
          type: 'dict-radio',
          dict: backendDict(DictEnum.OrgTypeEnum),
          form: {
            component: {
              optionName: 'a-radio-button',
            },
          },
        },
        shortName: {
          title: '简称',
          type: 'text',
        },

        sortValue: {
          title: '排序',
          type: 'number',
        },
        state: {
          title: '状态',
          type: 'dict-switch',
          addForm: {
            value: true,
          },
          dict: STATE_CONSTANT_DICT,
        },
        remarks: {
          title: '备注',
          type: 'textarea',
        },
      },
    },
  };
}

export const frontRules = (
  _crudExpose: CrudExpose,
  _mode: ActionEnum,
): FormRulesExt => {
  return {};
};
